package com.lqm.entity.home;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

@Entity
public class Comments implements Serializable {
    private int commentsId;
    private int replyId;
    private String commentsContent;
    @JsonFormat(shape = JsonFormat.Shape.STRING,pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime=new Date();
    private Integer status=1;
    private Integer isRead=0;
//    @JsonBackReference
    private HomeUser homeUser;
    @JsonBackReference
    private Project project;

    @Id
    @Column(name = "comments_id")
    public int getCommentsId() {
        return commentsId;
    }

    public void setCommentsId(int commentsId) {
        this.commentsId = commentsId;
    }

    @Basic
    @Column(name = "reply_id")
    public int getReplyId() {
        return replyId;
    }

    public void setReplyId(int replyId) {
        this.replyId = replyId;
    }

    @Basic
    @Column(name = "comments_content")
    public String getCommentsContent() {
        return commentsContent;
    }

    public void setCommentsContent(String commentsContent) {
        this.commentsContent = commentsContent;
    }

    @Basic
    @Column(name = "create_time")
    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @Basic
    @Column(name = "status")
    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }



    @Basic
    @Column(name = "is_read")
    public Integer getIsRead() {
        return isRead;
    }

    public void setIsRead(Integer isRead) {
        this.isRead = isRead;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Comments comments = (Comments) o;
        return commentsId == comments.commentsId &&
                replyId == comments.replyId &&
                Objects.equals(commentsContent, comments.commentsContent) &&
                Objects.equals(createTime, comments.createTime) &&
                Objects.equals(status, comments.status);
    }

    @Override
    public int hashCode() {

        return Objects.hash(commentsId, replyId, commentsContent, createTime, status);
    }

    @ManyToOne
    @JoinColumn(name = "comments_user_id", referencedColumnName = "id")
    public HomeUser getHomeUser() {
        return homeUser;
    }

    public void setHomeUser(HomeUser homeUser) {
        this.homeUser = homeUser;
    }

    @ManyToOne
    @JoinColumn(name = "comments_project_id", referencedColumnName = "project_id")
    public Project getProject() {
        return project;
    }

    public void setProject(Project project) {
        this.project = project;
    }

    @Override
    public String toString() {
        return "Comments{" +
                "commentsId=" + commentsId +
                ", replyId=" + replyId +
                ", commentsContent='" + commentsContent + '\'' +
                ", createTime=" + createTime +
                ", status=" + status +
                ", project=" + project +
                '}';
    }
}
